import java.util.Scanner;

class Node {
    public Node(int value, Node next) {
        this.value = value;
        this.next = next;
    }

    int value;
    Node next;
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Node firstNode = new Node(1, null);
        Node temp = firstNode;
        for (int i = 2; i <= n; i++) {
            if (i == n) {
                temp.next = new Node(i, firstNode);
                temp = null;
            } else {
                temp.next = new Node(i, null);
                temp = temp.next;
            }
        }

        int num2 = 1;
        int num = n;
        temp = firstNode;
        while (num != 1) {

            num2++;
            if (num2 != 3) {
                temp = temp.next;
            } else {
                num2 = 1;
                Node node = temp.next;
                temp.next = node.next;
                node.next = null;
                num--;
            }
        }
        System.out.println(temp.value);
    }
}
